import Vue from 'vue'
import Router from 'vue-router'
import Index from './views/Index'
import Home from './views/Home'
import FundList from './views/FundList'
import InfoShow from './views/InfoShow'
import Register from './views/Register'
import Login from './views/Login'
import Notfound from './views/404'


Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: '/index',
    },
    {
      path: '/index',
      component: Index,
      children:[
        {path:'', component: Home},
        {path:'/home', name:'home', component: Home},
        {path:'/infoshow', name:'infoshow', component: InfoShow},
        {path:'/fundlist', name:'fundlist', component: FundList},
      ]
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '*',
      name: '404',
      component: Notfound
    },
   
  ]
})

//路由守卫

router.beforeEach((to, from ,next) =>  {
  const islogin = localStorage.eletoken ? true : false
  if (to.path == "/login" || to.path == "/register"){
    next()
  } else {
    islogin ? next() : next("/login")
  }
})

export default router
